package send.weixin.service.impl;

import org.springframework.stereotype.Service;
import send.weixin.service.WeChatService;
import send.weixin.util.ShalUtil;

import java.util.Arrays;

/**
 * Created by lihong2 on 2017/2/25.
 */
@Service
public class WeChatServiceImpl implements WeChatService{

    //微信公众平台登录的签名校验
    private static final String token="shugentoken";
    public boolean checkSignature(String signature,String timestamp,String nonce) {
        //1、排序
        String [] arr = new String[]{token,timestamp,nonce};
        Arrays.sort(arr);
        //2、生成新的字符串
        StringBuffer content = new StringBuffer();
        for(int i=0;i<arr.length;i++){
            content.append(arr[i]);
        }
        //3、shal加密
        String temp = ShalUtil.getSha1(content.toString());
        return temp.equals(signature);
    }

}
